package com.mt.roll.process.controller;

import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.process.params.WorkSequenceParam;
import com.mt.roll.process.params.WorkSequenceQueryParam;
import com.mt.roll.process.service.WorkSequenceService;
import com.mt.roll.process.vo.EquipmentVo;
import com.mt.roll.process.vo.WorkSequenceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;

/**
 * @Author: liguanghao
 * @Date: 2021/3/31 16:21
 * @Version 1.0
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_PROCESS + "work-sequence")
@Slf4j
@Api(value = "工序管理", tags = "工序管理", hidden = false)
public class WorkSequenceController extends BaseController {

    @Autowired
    private WorkSequenceService workSequenceService;

    @PostMapping(value = "get")
    @ApiOperation(value = "获取详情")
    private R<WorkSequenceVo> get(@Validated @RequestBody IdParam idParam) {
        return workSequenceService.get(idParam);
    }

    @PostMapping(value = "page")
    @ApiOperation(value = "获取分页工序列表")
    private R<PageVo<WorkSequenceVo>> page(@Validated({PageGroup.class, Default.class}) @RequestBody WorkSequenceQueryParam workSequenceQueryParam) {
        return workSequenceService.page(workSequenceQueryParam);
    }

    @PostMapping(value = "list")
    @ApiOperation(value = "获取工序列表")
    private R<List<WorkSequenceVo>> list(@Validated({Default.class}) @RequestBody WorkSequenceQueryParam workSequenceQueryParam) {
        return workSequenceService.list(workSequenceQueryParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody WorkSequenceParam workSequenceParam) {
        return workSequenceService.add(workSequenceParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody WorkSequenceParam workSequenceParam) {
        return workSequenceService.update(workSequenceParam);
    }


    @PostMapping(value = "delete")
    @ApiOperation(value = "删除工艺")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return workSequenceService.delete(idParam);
    }

    @PostMapping(value = "equipmentlistList")
    @ApiOperation(value = "获取设备类型为“工艺设备”的设备列表")
    private R<List<EquipmentVo>> equipmentlist() {
        return workSequenceService.getEquipmentlist();
    }
}
